/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ile.Modelo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;

/**
 *
 * @author 
 */

@Entity
public class Materiales implements Serializable{
      @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column
    private String nombre;
    @Column
    private String codigo;
    
      
     @Lob
    @Column(length=16777215)
    private byte [] foto;
    
    @OneToMany(mappedBy = "material", cascade= CascadeType.PERSIST)//(mappedBy = "material", cascade = CascadeType.PERSIST)
    private  List<Marka> markas;

    public Materiales() {
        
        markas= new ArrayList<Marka>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public List<Marka> getMarkas() {
        return markas;
    }

    public void setMarkas(List<Marka> markas) {
        this.markas = markas;
    }

    public byte[] getFoto() {
        return foto;
    }

    public void setFoto(byte[] foto) {
        this.foto = foto;
    }
    
    
    
    
      public void  agregarM(Marka mm){
        if ((mm!=null)&& !markas.contains(mm)){
            this.markas.add(mm);
            mm.setMaterial(this);
        }
    }
}
